package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo. ExportProductDao;
import cn.itcast.domain.cargo. ExportProduct;
import cn.itcast.domain.cargo. ExportProductExample;
import cn.itcast.service.cargo. ExportProductService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;


@Service
public class  ExportProductServiceImpl implements  ExportProductService {

    @Autowired
    private  ExportProductDao  exportProductDao;

    /**
     * 报运商品分页
     * @param  exportProductExample 分页查询的参数
     * @param pageNum 当前页
     * @param pageSize 页大小
     * @return
     */
    @Override
    public PageInfo< ExportProduct> findByPage( ExportProductExample  exportProductExample, int pageNum, int pageSize) {
        //设置开始页与也买你大小
        PageHelper.startPage(pageNum, pageSize);
        //查询全部
        List< ExportProduct>  exportProductList =  exportProductDao.selectByExample( exportProductExample);
        PageInfo< ExportProduct> pageInfo = new PageInfo<>( exportProductList);
        return pageInfo;
    }
    //查询所有的报运商品
    @Override
    public List< ExportProduct> findAll( ExportProductExample  exportProductExample) {
        return  exportProductDao.selectByExample( exportProductExample);
    }

    @Override
    public  ExportProduct findById(String id) {
        return  exportProductDao.selectByPrimaryKey(id);
    }

    @Override
    public void save( ExportProduct exportProduct) {
         exportProduct.setId(UUID.randomUUID().toString());

         exportProduct.setCreateTime(new Date());
         exportProduct.setUpdateTime(new Date());
         exportProductDao.insertSelective(exportProduct);
    }

    @Override //保存报运商品
    public void update( ExportProduct  exportProduct) {
         exportProduct.setUpdateTime(new Date());
         exportProductDao.updateByPrimaryKeySelective(exportProduct);

    }

    @Override
    public void delete(String id) {
         exportProductDao.deleteByPrimaryKey(id);

    }
  
}
